package dongze.com.ckdj.adapter;

import android.database.DataSetObserver;
import android.databinding.adapters.SpinnerBindingAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import java.util.List;

import dongze.com.ckdj.data.entity.response.InspectionSection;

/**
 * Created by fanqwz on 2017/7/26.
 */

public class InformationSpinnerAdapter implements SpinnerAdapter {
    final List<InspectionSection> list;
    
    public InformationSpinnerAdapter(List<InspectionSection> list) {
        this.list = list;
        //// TODO: 2017/7/26  
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
        }

        TextView textView = (TextView) convertView.findViewById(android.R.id.text1);

        if (position == 0) {
            textView.setText("请选择：");
        } else if (position <= getCount()){
            textView.setText(list.get(position - 1).getNode_name());
        }

        return convertView;
    }

    @Override
    public void registerDataSetObserver(DataSetObserver observer) {

    }

    @Override
    public void unregisterDataSetObserver(DataSetObserver observer) {

    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size() + 1;
    }

    @Override
    public Object getItem(int position) {
        return list == null ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getDropDownView(position, convertView, parent);
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        return 1;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }
}
